package edu.whu.service.impl;

import edu.whu.dao.SupplierRepository;
import edu.whu.entity.Supplier;
import edu.whu.exception.ProductException;
import edu.whu.service.SupplierService;

public class SupplierServiceImpl implements SupplierService {
    private final SupplierRepository repository;

    public SupplierServiceImpl(SupplierRepository repository) {
        this.repository = repository;
    }

    public Supplier save(Supplier supplier){
       return repository.save(supplier);
    }

    public void deleteById(int id) throws ProductException {

        try {
            repository.deleteById(id);
        }catch (Exception e){
            throw  new ProductException("删除的商品供应商找不到!");
        }

    }

    public Supplier selectById(Integer id){
        return  repository.findById(id).get();
    }


}
